cmake_minimum_required(VERSION 3.10)
get_filename_component(PRJ_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(${PRJ_NAME})

add_library(${PROJECT_NAME}
        WGSMPlayer.cpp
        WGSMPlayer.h
        )

find_package(PkgConfig REQUIRED)
if (FALSE)
    pkg_search_module(OPUSFILE REQUIRED IMPORTED_TARGET opusfile)
    target_link_libraries(${PROJECT_NAME} PkgConfig::OPUSFILE
            # for opusfile url open
            -L${OPUSFILE_LIBRARY_DIRS} opusurl
            )

else ()
    # using my own build opusfile package to fix http unable to seek issue
    # that's becuase of the opusfile library send http request using HTTP 1.0
    # in http.c::2399->op_http_stream_open

    if (WIN32)
        add_subdirectory(${OPUSFILE_HOME} ${OPUSFILE_HOME}/cmake-build-debug)

        set(SDL2_INCLUDE_DIRS "${WINBUILD_HOME}/include/sdl2")
        set(SDL2_LIBRARIES sdl2)
    else ()
        #        this is MAC opusfile build dir
        set(OPUSFILE_HOME /Users/guoshunw/Downloads/opusfile/build/install)
        target_include_directories(${PROJECT_NAME} PUBLIC
                ${OPUSFILE_HOME}/include/opus
                )
        target_link_libraries(${PROJECT_NAME}
                -L${OPUSFILE_HOME}/lib
                opusfile
                opusurl
                )
    endif ()

endif ()

target_include_directories(${PROJECT_NAME} PUBLIC
        ../..
        ${OPUS_INCLUDE_DIRS}
        ${OPUSFILE_INCLUDE_DIRS}
        ${OGG_INCLUDE_DIRS}
        )


if (WIN32)

else ()
    find_package(sdl2 REQUIRED)
    pkg_search_module(OPUS REQUIRED IMPORTED_TARGET opus)
    pkg_search_module(OGG REQUIRED IMPORTED_TARGET ogg)

endif ()


#message("SDL INCLUDE DIR: ${SDL2_INCLUDE_DIRS}")

target_include_directories(${PROJECT_NAME} PUBLIC
        ../..

        ${SDL2_INCLUDE_DIRS}
        ${OPUS_INCLUDE_DIRS}
        ${OGG_INCLUDE_DIRS}
        )

target_link_libraries(${PROJECT_NAME}
        ${OGG_LIBRARIES}
        ${OPUS_LIBRARIES}
        pthread
        )

#if(WIN32)
#    https://stackoverflow.com/questions/17048072/sdl-2-undefined-reference-to-winmain16-and-several-sdl-functions
# this would lead to out of memory
#    target_link_libraries(${PROJECT_NAME}
#            mingw32
#            sdl2main
#            )
#endif()

target_link_libraries(${PROJECT_NAME}
        ${SDL2_LIBRARIES}
        )
